#!/usr/bin/python3.2

#voir pour pièces jointes

import smtplib
import imaplib
import os
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


def sendHtmlMail(subject,content,recipient):
	sender = "ialuchiana@gmail.com"
	#recipient = "lorkscorguar@gmail.com"

	# Create message container - the correct MIME type is multipart/alternative.
	msg = MIMEMultipart('alternative')
	msg['Subject'] = subject
	msg['From'] = sender
	msg['To'] = recipient
	# Create the body of the message (a plain-text and an HTML version).
	text = content
	html = content
	# Record the MIME types of both parts - text/plain and text/html.
	part1 = MIMEText(text, 'plain')
	part2 = MIMEText(html, 'html')
	# Attach parts into message container.
	# According to RFC 2046, the last part of a multipart message, in this case
	# the HTML message, is best and preferred.
	msg.attach(part1)
	msg.attach(part2)
	# Send the message via local SMTP server.
	s = smtplib.SMTP('smtp.gmail.com','587')
	s.ehlo()
	s.starttls()
	s.login(sender,'luchiana1@')
	# sendmail function takes 3 arguments: sender's address, recipient's address
	# and message to send - here it is sent as one string.
	s.sendmail(sender, recipient, msg.as_string())
	s.quit()

def sendTextMail(subject,content,dest):
	fromaddr = "ialuchiana@gmail.com"
	smtp = smtplib.SMTP('smtp.gmail.com','587')
	smtp.ehlo()
	smtp.starttls()
	smtp.login('ialuchiana@gmail.com','luchiana1@')
	smtp.sendmail(fromaddr,dest,content)
	smtp.close()

def checkGmail():
    obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
    obj.login('ialuchiana@gmail.com','luchiana1@')
    obj.select()
    rep=obj.search(None,'UnSeen')
    nb=len(str(rep[1]).split(" "))
    return nb

